﻿using SD.Toolkits.Mapper;
using SlamDunk.MES.Domain.Entities.MaintenanceContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.FoundationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.MaintenanceContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ResourceContext;
using System;
using System.Collections.Generic;

namespace SlamDunk.MES.AppService.Maps
{
    /// <summary>
    /// 维护相关映射
    /// </summary>
    public static class MaintenanceMap
    {
        #region # 设备资产映射 —— static EquipmentAssetInfo ToDTO(this EquipmentAsset...
        /// <summary>
        /// 设备资产映射
        /// </summary>
        public static EquipmentAssetInfo ToDTO(this EquipmentAsset equipmentAsset, IDictionary<Guid, EquipmentInfo> equipmentInfos, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            EquipmentAssetInfo assetInfo = equipmentAsset.Map<EquipmentAsset, EquipmentAssetInfo>();
            assetInfo.EquipmentInfo = equipmentInfos?[equipmentAsset.EquipmentId];
            assetInfo.FacilityInfo = equipmentAsset.FacilityId.HasValue
                ? facilityInfos?[equipmentAsset.FacilityId.Value]
                : null;

            return assetInfo;
        }
        #endregion

        #region # 设备维护类映射 —— static EquipmentMaintainClassInfo ToDTO(this EquipmentMaintainClass...
        /// <summary>
        /// 设备维护类映射
        /// </summary>
        public static EquipmentMaintainClassInfo ToDTO(this EquipmentMaintainClass maintainClass, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            EquipmentMaintainClassInfo maintainClassInfo = maintainClass.Map<EquipmentMaintainClass, EquipmentMaintainClassInfo>();
            maintainClassInfo.FacilityInfo = maintainClass.FacilityId.HasValue
                ? facilityInfos?[maintainClass.FacilityId.Value]
                : null;

            return maintainClassInfo;
        }
        #endregion

        #region # 设备维护记录映射 —— static EquipmentMaintenanceInfo ToDTO(this EquipmentMaintenance...
        /// <summary>
        /// 设备维护记录映射
        /// </summary>
        public static EquipmentMaintenanceInfo ToDTO(this EquipmentMaintenance maintenance, IDictionary<Guid, EquipmentMaintainClassInfo> maintainClassInfos, IDictionary<Guid, EquipmentAssetInfo> equipmentAssetInfos, IDictionary<Guid, FacilityInfo> facilityInfos)
        {
            EquipmentMaintenanceInfo maintenanceInfo = maintenance.Map<EquipmentMaintenance, EquipmentMaintenanceInfo>();
            maintenanceInfo.EquipmentMaintainClassInfo = maintainClassInfos?[maintenance.EquipmentMaintainClassId];
            maintenanceInfo.EquipmentAssetInfo = equipmentAssetInfos?[maintenance.EquipmentAssetId];
            maintenanceInfo.FacilityInfo = maintenance.FacilityId.HasValue
                ? facilityInfos?[maintenance.FacilityId.Value]
                : null;

            return maintenanceInfo;
        }
        #endregion
    }
}
